package airthmetic.exercise.stack;

import java.util.Stack;

public class _155_最小栈不借助第二个栈写法 {
    private Stack<Integer> stack;
    private Integer min = Integer.MAX_VALUE;

    public _155_最小栈不借助第二个栈写法() {
        stack = new Stack<Integer>();
    }

    public void push(int val) {
        if (val <= min){
            stack.push(min);
            min = val;
        }
       stack.push(val);
    }

    public void pop() {
        if(stack.pop() == min){
            min = stack.pop();
        }
    }

    public int top() {
       return stack.peek();
    }

    public int getMin() {
        return min;
    }
}
